home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / Make / source / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-27  |  16.6 KB  |  771 lines

  1. /* Miscellaneous generic support functions for GNU Make.
  2. Copyright (C) 1988,89,90,91,92,93,94,95,97 Free Software Foundation, Inc.
  3. This file is part of GNU Make.
  4.  
  5. GNU Make is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. GNU Make is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with GNU Make; see the file COPYING.  If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "make.h"
  20. #include "dep.h"
  21.  
  22.  
  23. /* Compare strings *S1 and *S2.
  24.    Return negative if the first is less, positive if it is greater,
  25.    zero if they are equal.  */
  26.  
  27. int
  28. alpha_compare (s1, s2)
  29.      char **s1, **s2;
  30. {
  31.   if (**s1 != **s2)
  32.     return **s1 - **s2;
  33.   return strcmp (*s1, *s2);
  34. }
  35.  
  36. /* Discard each backslash-newline combination from LINE.
  37.    Backslash-backslash-newline combinations become backslash-newlines.
  38.    This is done by copying the text at LINE into itself.  */
  39.  
  40. void
  41. collapse_continuations (line)
  42.      char *line;
  43. {
  44.   register char *in, *out, *p;
  45.   register int backslash;
  46.   register unsigned int bs_write;
  47.  
  48.   in = index (line, '\n');
  49.   if (in == 0)
  50.     return;
  51.  
  52.   out = in;
  53.   while (out > line && out[-1] == '\\')
  54.     --out;
  55.  
  56.   while (*in != '\0')
  57.     {
  58.       /* BS_WRITE gets the number of quoted backslashes at
  59.      the end just before IN, and BACKSLASH gets nonzero
  60.      if the next character is quoted.  */
  61.       backslash = 0;
  62.       bs_write = 0;
  63.       for (p = in - 1; p >= line && *p == '\\'; --p)
  64.     {
  65.       if (backslash)
  66.         ++bs_write;
  67.       backslash = !backslash;
  68.  
  69.       /* It should be impossible to go back this far without exiting,
  70.          but if we do, we can't get the right answer.  */
  71.       if (in == out - 1)
  72.         abort ();
  73.     }
  74.  
  75.       /* Output the appropriate number of backslashes.  */
  76.       while (bs_write-- > 0)
  77.     *out++ = '\\';
  78.  
  79.       /* Skip the newline.  */
  80.       ++in;
  81.  
  82.       /* If the newline is quoted, discard following whitespace
  83.      and any preceding whitespace; leave just one space.  */
  84.       if (backslash)
  85.     {
  86.       in = next_token (in);
  87.       while (out > line && isblank (out[-1]))
  88.         --out;
  89.       *out++ = ' ';
  90.     }
  91.       else
  92.     /* If the newline isn't quoted, put it in the output.  */
  93.     *out++ = '\n';
  94.  
  95.       /* Now copy the following line to the output.
  96.      Stop when we find backslashes followed by a newline.  */
  97.       while (*in != '\0')
  98.     if (*in == '\\')
  99.       {
  100.         p = in + 1;
  101.         while (*p == '\\')
  102.           ++p;
  103.         if (*p == '\n')
  104.           {
  105.         in = p;
  106.         break;
  107.           }
  108.         while (in < p)
  109.           *out++ = *in++;
  110.       }
  111.     else
  112.       *out++ = *in++;
  113.     }
  114.  
  115.   *out = '\0';
  116. }
  117.  
  118.  
  119. /* Remove comments from LINE.
  120.    This is done by copying the text at LINE onto itself.  */
  121.  
  122. void
  123. remove_comments (line)
  124.      char *line;
  125. {
  126.   char *comment;
  127.  
  128.   comment = find_char_unquote (line, "#", 0);
  129.  
  130.   if (comment != 0)
  131.     /* Cut off the line at the #.  */
  132.     *comment = '\0';
  133. }
  134.  
  135. /* Print N spaces (used by DEBUGPR for target-depth).  */
  136.  
  137. void
  138. print_spaces (n)
  139.      register unsigned int n;
  140. {
  141.   while (n-- > 0)
  142.     putchar (' ');
  143. }
  144.  
  145.  
  146. /* Return a newly-allocated string whose contents
  147.    concatenate those of s1, s2, s3.  */
  148.  
  149. char *
  150. concat (s1, s2, s3)
  151.      register char *s1, *s2, *s3;
  152. {
  153.   register unsigned int len1, len2, len3;
  154.   register char *result;
  155.  
  156.   len1 = *s1 != '\0' ? strlen (s1) : 0;
  157.   len2 = *s2 != '\0' ? strlen (s2) : 0;
  158.   len3 = *s3 != '\0' ? strlen (s3) : 0;
  159.  
  160.   result = (char *) xmalloc (len1 + len2 + len3 + 1);
  161.  
  162.   if (*s1 != '\0')
  163.     bcopy (s1, result, len1);
  164.   if (*s2 != '\0')
  165.     bcopy (s2, result + len1, len2);
  166.   if (*s3 != '\0')
  167.     bcopy (s3, result + len1 + len2, len3);
  168.   *(result + len1 + len2 + len3) = '\0';
  169.  
  170.   return result;
  171. }
  172.  
  173. /* Print a message on stdout.  */
  174.  
  175. void
  176. message (prefix, s1, s2, s3, s4, s5, s6)
  177.      int prefix;
  178.      char *s1, *s2, *s3, *s4, *s5, *s6;
  179. {
  180.   log_working_directory (1);
  181.  
  182.   if (s1 != 0)
  183.     {
  184.       if (prefix)
  185.     {
  186.       if (makelevel == 0)
  187.         printf ("%s: ", program);
  188.       else
  189.         printf ("%s[%u]: ", program, makelevel);
  190.     }
  191.       printf (s1, s2, s3, s4, s5, s6);
  192.       putchar ('\n');
  193.     }
  194.  
  195.   fflush (stdout);
  196. }
  197.  
  198. /* Print an error message and exit.  */
  199.  
  200. /* VARARGS1 */
  201. void
  202. fatal (s1, s2, s3, s4, s5, s6)
  203.      char *s1, *s2, *s3, *s4, *s5, *s6;
  204. {
  205.   log_working_directory (1);
  206.  
  207.   if (makelevel == 0)
  208.     fprintf (stderr, "%s: *** ", program);
  209.   else
  210.     fprintf (stderr, "%s[%u]: *** ", program, makelevel);
  211.   fprintf (stderr, s1, s2, s3, s4, s5, s6);
  212.   fputs (".  Stop.\n", stderr);
  213.  
  214.   die (2);
  215. }
  216.  
  217. /* Print error message.  `s1' is printf control string, `s2' is arg for it. */
  218.  
  219. /* VARARGS1 */
  220.  
  221. void
  222. error (s1, s2, s3, s4, s5, s6)
  223.      char *s1, *s2, *s3, *s4, *s5, *s6;
  224. {
  225.   log_working_directory (1);
  226.  
  227.   if (makelevel == 0)
  228.     fprintf (stderr, "%s: ", program);
  229.   else
  230.     fprintf (stderr, "%s[%u]: ", program, makelevel);
  231.   fprintf (stderr, s1, s2, s3, s4, s5, s6);
  232.   putc ('\n', stderr);
  233.   fflush (stderr);
  234. }
  235.  
  236. void
  237. makefile_error (file, lineno, s1, s2, s3, s4, s5, s6)
  238.      char *file;
  239.      unsigned int lineno;
  240.      char *s1, *s2, *s3, *s4, *s5, *s6;
  241. {
  242.   log_working_directory (1);
  243.  
  244.   fprintf (stderr, "%s:%u: ", file, lineno);
  245.   fprintf (stderr, s1, s2, s3, s4, s5, s6);
  246.   putc ('\n', stderr);
  247.   fflush (stderr);
  248. }
  249.  
  250. void
  251. makefile_fatal (file, lineno, s1, s2, s3, s4, s5, s6)
  252.      char *file;
  253.      unsigned int lineno;
  254.      char *s1, *s2, *s3, *s4, *s5, *s6;
  255. {
  256.   log_working_directory (1);
  257.  
  258.   fprintf (stderr, "%s:%u: *** ", file, lineno);
  259.   fprintf (stderr, s1, s2, s3, s4, s5, s6);
  260.   fputs (".  Stop.\n", stderr);
  261.  
  262.   die (2);
  263. }
  264.  
  265. #ifndef HAVE_STRERROR
  266.  
  267. #undef    strerror
  268.  
  269. char *
  270. strerror (errnum)
  271.      int errnum;
  272. {
  273.   extern int errno, sys_nerr;
  274. #ifndef __DECC
  275.   extern char *sys_errlist[];
  276. #endif
  277.   static char buf[] = "Unknown error 12345678901234567890";
  278.  
  279.   if (errno < sys_nerr)
  280.     return sys_errlist[errnum];
  281.  
  282.   sprintf (buf, "Unknown error %d", errnum);
  283.   return buf;
  284. }
  285. #endif
  286.  
  287. /* Print an error message from errno.  */
  288.  
  289. void
  290. perror_with_name (str, name)
  291.      char *str, *name;
  292. {
  293.   error ("%s%s: %s", str, name, strerror (errno));
  294. }
  295.  
  296. /* Print an error message from errno and exit.  */
  297.  
  298. void
  299. pfatal_with_name (name)
  300.      char *name;
  301. {
  302.   fatal ("%s: %s", name, strerror (errno));
  303.  
  304.   /* NOTREACHED */
  305. }
  306.  
  307. /* Like malloc but get fatal error if memory is exhausted.  */
  308.  
  309. #undef xmalloc
  310. #undef xrealloc
  311.  
  312. char *
  313. xmalloc (size)
  314.      unsigned int size;
  315. {
  316.   char *result = (char *) malloc (size);
  317.   if (result == 0)
  318.     fatal ("virtual memory exhausted");
  319.   return result;
  320. }
  321.  
  322.  
  323. char *
  324. xrealloc (ptr, size)
  325.      char *ptr;
  326.      unsigned int size;
  327. {
  328.   char *result = (char *) realloc (ptr, size);
  329.   if (result == 0)
  330.     fatal ("virtual memory exhausted");
  331.   return result;
  332. }
  333.  
  334. char *
  335. savestring (str, length)
  336.      char *str;
  337.      unsigned int length;
  338. {
  339.   register char *out = (char *) xmalloc (length + 1);
  340.   if (length > 0)
  341.     bcopy (str, out, length);
  342.   out[length] = '\0';
  343.   return out;
  344. }
  345.  
  346. /* Search string BIG (length BLEN) for an occurrence of
  347.    string SMALL (length SLEN).  Return a pointer to the
  348.    beginning of the first occurrence, or return nil if none found.  */
  349.  
  350. char *
  351. sindex (big, blen, small, slen)
  352.      char *big;
  353.      unsigned int blen;
  354.      char *small;
  355.      unsigned int slen;
  356. {
  357.   register unsigned int b;
  358.  
  359.   if (blen < 1)
  360.     blen = strlen (big);
  361.   if (slen < 1)
  362.     slen = strlen (small);
  363.  
  364.   for (b = 0; b < blen; ++b)
  365.     if (big[b] == *small && !strncmp (&big[b + 1], small + 1, slen - 1))
  366.       return (&big[b]);
  367.  
  368.   return 0;
  369. }
  370.  
  371. /* Limited INDEX:
  372.    Search through the string STRING, which ends at LIMIT, for the character C.
  373.    Returns a pointer to the first occurrence, or nil if none is found.
  374.    Like INDEX except that the string searched ends where specified
  375.    instead of at the first null.  */
  376.  
  377. char *
  378. lindex (s, limit, c)
  379.      register char *s, *limit;
  380.      int c;
  381. {
  382.   while (s < limit)
  383.     if (*s++ == c)
  384.       return s - 1;
  385.  
  386.   return 0;
  387. }
  388.  
  389. /* Return the address of the first whitespace or null in the string S.  */
  390.  
  391. char *
  392. end_of_token (s)
  393.      char *s;
  394. {
  395.   while (*s != '\0' && !isblank (*s))
  396.     ++s;
  397.   return s;
  398. }
  399.  
  400. #ifdef WINDOWS32
  401. /*
  402.  * Same as end_of_token, but take into account a stop character
  403.  */
  404. char *
  405. end_of_token_w32 (s, stopchar)
  406.      char *s;
  407.      char stopchar;
  408. {
  409.   register char *p = s;
  410.   register int backslash = 0;
  411.  
  412.   while (*p != '\0' && *p != stopchar && (backslash || !isblank (*p)))
  413.     {
  414.       if (*p++ == '\\')
  415.         {
  416.           backslash = !backslash;
  417.           while (*p == '\\')
  418.             {
  419.               backslash = !backslash;
  420.               ++p;
  421.             }
  422.         }
  423.       else
  424.         backslash = 0;
  425.     }
  426.  
  427.   return p;
  428. }
  429. #endif
  430.  
  431. /* Return the address of the first nonwhitespace or null in the string S.  */
  432.  
  433. char *
  434. next_token (s)
  435.      char *s;
  436. {
  437.   register char *p = s;
  438.  
  439.   while (isblank (*p))
  440.     ++p;
  441.   return p;
  442. }
  443.  
  444. /* Find the next token in PTR; return the address of it, and store the
  445.    length of the token into *LENGTHPTR if LENGTHPTR is not nil.  */
  446.  
  447. char *
  448. find_next_token (ptr, lengthptr)
  449.      char **ptr;
  450.      unsigned int *lengthptr;
  451. {
  452.   char *p = next_token (*ptr);
  453.   char *end;
  454.  
  455.   if (*p == '\0')
  456.     return 0;
  457.  
  458.   *ptr = end = end_of_token (p);
  459.   if (lengthptr != 0)
  460.     *lengthptr = end - p;
  461.   return p;
  462. }
  463.  
  464. /* Copy a chain of `struct dep', making a new chain
  465.    with the same contents as the old one.  */
  466.  
  467. struct dep *
  468. copy_dep_chain (d)
  469.      register struct dep *d;
  470. {
  471.   register struct dep *c;
  472.   struct dep *firstnew = 0;
  473.   struct dep *lastnew;
  474.  
  475.   while (d != 0)
  476.     {
  477.       c = (struct dep *) xmalloc (sizeof (struct dep));
  478.       bcopy ((char *) d, (char *) c, sizeof (struct dep));
  479.       if (c->name != 0)
  480.     c->name = savestring (c->name, strlen (c->name));
  481.       c->next = 0;
  482.       if (firstnew == 0)
  483.     firstnew = lastnew = c;
  484.       else
  485.     lastnew = lastnew->next = c;
  486.  
  487.       d = d->next;
  488.     }
  489.  
  490.   return firstnew;
  491. }
  492.  
  493. #ifdef    iAPX286
  494. /* The losing compiler on this machine can't handle this macro.  */
  495.  
  496. char *
  497. dep_name (dep)
  498.      struct dep *dep;
  499. {
  500.   return dep->name == 0 ? dep->file->name : dep->name;
  501. }
  502. #endif
  503.  
  504. #ifdef    GETLOADAVG_PRIVILEGED
  505.  
  506. #ifdef POSIX
  507.  
  508. /* Hopefully if a system says it's POSIX.1 and has the setuid and setgid
  509.    functions, they work as POSIX.1 says.  Some systems (Alpha OSF/1 1.2,
  510.    for example) which claim to be POSIX.1 also have the BSD setreuid and
  511.    setregid functions, but they don't work as in BSD and only the POSIX.1
  512.    way works.  */
  513.  
  514. #undef HAVE_SETREUID
  515. #undef HAVE_SETREGID
  516.  
  517. #else    /* Not POSIX.  */
  518.  
  519. /* Some POSIX.1 systems have the seteuid and setegid functions.  In a
  520.    POSIX-like system, they are the best thing to use.  However, some
  521.    non-POSIX systems have them too but they do not work in the POSIX style
  522.    and we must use setreuid and setregid instead.  */
  523.  
  524. #undef HAVE_SETEUID
  525. #undef HAVE_SETEGID
  526.  
  527. #endif    /* POSIX.  */
  528.  
  529. #ifndef    HAVE_UNISTD_H
  530. extern int getuid (), getgid (), geteuid (), getegid ();
  531. extern int setuid (), setgid ();
  532. #ifdef HAVE_SETEUID
  533. extern int seteuid ();
  534. #else
  535. #ifdef    HAVE_SETREUID
  536. extern int setreuid ();
  537. #endif    /* Have setreuid.  */
  538. #endif    /* Have seteuid.  */
  539. #ifdef HAVE_SETEGID
  540. extern int setegid ();
  541. #else
  542. #ifdef    HAVE_SETREGID
  543. extern int setregid ();
  544. #endif    /* Have setregid.  */
  545. #endif    /* Have setegid.  */
  546. #endif    /* No <unistd.h>.  */
  547.  
  548. /* Keep track of the user and group IDs for user- and make- access.  */
  549. static int user_uid = -1, user_gid = -1, make_uid = -1, make_gid = -1;
  550. #define    access_inited    (user_uid != -1)
  551. static enum { make, user } current_access;
  552.  
  553.  
  554. /* Under -d, write a message describing the current IDs.  */
  555.  
  556. static void
  557. log_access (flavor)
  558.      char *flavor;
  559. {
  560.   if (! debug_flag)
  561.     return;
  562.  
  563.   /* All the other debugging messages go to stdout,
  564.      but we write this one to stderr because it might be
  565.      run in a child fork whose stdout is piped.  */
  566.  
  567.   fprintf (stderr, "%s access: user %d (real %d), group %d (real %d)\n",
  568.        flavor, geteuid (), getuid (), getegid (), getgid ());
  569.   fflush (stderr);
  570. }
  571.  
  572.  
  573. static void
  574. init_access ()
  575. {
  576. #ifndef VMS
  577.   user_uid = getuid ();
  578.   user_gid = getgid ();
  579.  
  580.   make_uid = geteuid ();
  581.   make_gid = getegid ();
  582.  
  583.   /* Do these ever fail?  */
  584.   if (user_uid == -1 || user_gid == -1 || make_uid == -1 || make_gid == -1)
  585.     pfatal_with_name ("get{e}[gu]id");
  586.  
  587.   log_access ("Initialized");
  588.  
  589.   current_access = make;
  590. #endif
  591. }
  592.  
  593. #endif    /* GETLOADAVG_PRIVILEGED */
  594.  
  595. /* Give the process appropriate permissions for access to
  596.    user data (i.e., to stat files, or to spawn a child process).  */
  597. void
  598. user_access ()
  599. {
  600. #ifdef    GETLOADAVG_PRIVILEGED
  601.  
  602.   if (!access_inited)
  603.     init_access ();
  604.  
  605.   if (current_access == user)
  606.     return;
  607.  
  608.   /* We are in "make access" mode.  This means that the effective user and
  609.      group IDs are those of make (if it was installed setuid or setgid).
  610.      We now want to set the effective user and group IDs to the real IDs,
  611.      which are the IDs of the process that exec'd make.  */
  612.  
  613. #ifdef    HAVE_SETEUID
  614.  
  615.   /* Modern systems have the seteuid/setegid calls which set only the
  616.      effective IDs, which is ideal.  */
  617.  
  618.   if (seteuid (user_uid) < 0)
  619.     pfatal_with_name ("user_access: seteuid");
  620.  
  621. #else    /* Not HAVE_SETEUID.  */
  622.  
  623. #ifndef    HAVE_SETREUID
  624.  
  625.   /* System V has only the setuid/setgid calls to set user/group IDs.
  626.      There is an effective ID, which can be set by setuid/setgid.
  627.      It can be set (unless you are root) only to either what it already is
  628.      (returned by geteuid/getegid, now in make_uid/make_gid),
  629.      the real ID (return by getuid/getgid, now in user_uid/user_gid),
  630.      or the saved set ID (what the effective ID was before this set-ID
  631.      executable (make) was exec'd).  */
  632.  
  633.   if (setuid (user_uid) < 0)
  634.     pfatal_with_name ("user_access: setuid");
  635.  
  636. #else    /* HAVE_SETREUID.  */
  637.  
  638.   /* In 4BSD, the setreuid/setregid calls set both the real and effective IDs.
  639.      They may be set to themselves or each other.  So you have two alternatives
  640.      at any one time.  If you use setuid/setgid, the effective will be set to
  641.      the real, leaving only one alternative.  Using setreuid/setregid, however,
  642.      you can toggle between your two alternatives by swapping the values in a
  643.      single setreuid or setregid call.  */
  644.  
  645.   if (setreuid (make_uid, user_uid) < 0)
  646.     pfatal_with_name ("user_access: setreuid");
  647.  
  648. #endif    /* Not HAVE_SETREUID.  */
  649. #endif    /* HAVE_SETEUID.  */
  650.  
  651. #ifdef    HAVE_SETEGID
  652.   if (setegid (user_gid) < 0)
  653.     pfatal_with_name ("user_access: setegid");
  654. #else
  655. #ifndef    HAVE_SETREGID
  656.   if (setgid (user_gid) < 0)
  657.     pfatal_with_name ("user_access: setgid");
  658. #else
  659.   if (setregid (make_gid, user_gid) < 0)
  660.     pfatal_with_name ("user_access: setregid");
  661. #endif
  662. #endif
  663.  
  664.   current_access = user;
  665.  
  666.   log_access ("User");
  667.  
  668. #endif    /* GETLOADAVG_PRIVILEGED */
  669. }
  670.  
  671. /* Give the process appropriate permissions for access to
  672.    make data (i.e., the load average).  */
  673. void
  674. make_access ()
  675. {
  676. #ifdef    GETLOADAVG_PRIVILEGED
  677.  
  678.   if (!access_inited)
  679.     init_access ();
  680.  
  681.   if (current_access == make)
  682.     return;
  683.  
  684.   /* See comments in user_access, above.  */
  685.  
  686. #ifdef    HAVE_SETEUID
  687.   if (seteuid (make_uid) < 0)
  688.     pfatal_with_name ("make_access: seteuid");
  689. #else
  690. #ifndef    HAVE_SETREUID
  691.   if (setuid (make_uid) < 0)
  692.     pfatal_with_name ("make_access: setuid");
  693. #else
  694.   if (setreuid (user_uid, make_uid) < 0)
  695.     pfatal_with_name ("make_access: setreuid");
  696. #endif
  697. #endif
  698.  
  699. #ifdef    HAVE_SETEGID
  700.   if (setegid (make_gid) < 0)
  701.     pfatal_with_name ("make_access: setegid");
  702. #else
  703. #ifndef    HAVE_SETREGID
  704.   if (setgid (make_gid) < 0)
  705.     pfatal_with_name ("make_access: setgid");
  706. #else
  707.   if (setregid (user_gid, make_gid) < 0)
  708.     pfatal_with_name ("make_access: setregid");
  709. #endif
  710. #endif
  711.  
  712.   current_access = make;
  713.  
  714.   log_access ("Make");
  715.  
  716. #endif    /* GETLOADAVG_PRIVILEGED */
  717. }
  718.  
  719. /* Give the process appropriate permissions for a child process.
  720.    This is like user_access, but you can't get back to make_access.  */
  721. void
  722. child_access ()
  723. {
  724. #ifdef    GETLOADAVG_PRIVILEGED
  725.  
  726.   if (!access_inited)
  727.     abort ();
  728.  
  729.   /* Set both the real and effective UID and GID to the user's.
  730.      They cannot be changed back to make's.  */
  731.  
  732. #ifndef    HAVE_SETREUID
  733.   if (setuid (user_uid) < 0)
  734.     pfatal_with_name ("child_access: setuid");
  735. #else
  736.   if (setreuid (user_uid, user_uid) < 0)
  737.     pfatal_with_name ("child_access: setreuid");
  738. #endif
  739.  
  740. #ifndef    HAVE_SETREGID
  741.   if (setgid (user_gid) < 0)
  742.     pfatal_with_name ("child_access: setgid");
  743. #else
  744.   if (setregid (user_gid, user_gid) < 0)
  745.     pfatal_with_name ("child_access: setregid");
  746. #endif
  747.  
  748.   log_access ("Child");
  749.  
  750. #endif    /* GETLOADAVG_PRIVILEGED */
  751. }
  752.  
  753. #ifdef NEED_GET_PATH_MAX
  754. unsigned int
  755. get_path_max ()
  756. {
  757.   static unsigned int value;
  758.  
  759.   if (value == 0)
  760.     {
  761.       long int x = pathconf ("/", _PC_PATH_MAX);
  762.       if (x > 0)
  763.     value = x;
  764.       else
  765.     return MAXPATHLEN;
  766.     }
  767.  
  768.   return value;
  769. }
  770. #endif
  771.